<template>
	<div class="padding" v-loading="loading">
		<div class="f-between">
			<h3>养老机构消防改造设计方案</h3>
		</div>
		<div class="mt12" v-if="!isDetail">
			<AplidUpload
				v-model="modelData.imageList2"
				listType="picture-card"
				:showFileList="false"
				:fileType="uploadType.fileMetaType"
				name="养老机构消防改造设计方案"
				uploadTip="上传养老机构消防改造设计方案"
				:limit="1"
				:multiple="false"
				:disabled="isDetail"
				@change="uploadChange"
			></AplidUpload>
		</div>
		<div style="width: 150px" v-else>
			<FileList :src="modelData.imageList2" :only-ready="true" :showFileList="true"> </FileList>
		</div>
		<div class="f-between">
			<h3>养老机构消防改造投标材料</h3>
		</div>
		<div class="mt12" v-if="!isDetail">
			<AplidUpload
				v-model="modelData.imageList3"
				listType="picture-card"
				:showFileList="false"
				:fileType="uploadType.fileMetaType"
				name="养老机构消防改造投标材料"
				uploadTip="上传养老机构消防改造投标材料"
				:limit="1"
				:multiple="false"
				:disabled="isDetail"
				@change="uploadChange"
			></AplidUpload>
		</div>
		<div style="width: 150px" v-else>
			<FileList :src="modelData.imageList3" :only-ready="true" :showFileList="true"> </FileList>
		</div>
		<div class="f-between">
			<h3>养老机构消防竣工验收报告</h3>
		</div>
		<div class="mt12" v-if="!isDetail">
			<AplidUpload
				v-model="modelData.imageList4"
				listType="picture-card"
				:showFileList="false"
				:fileType="uploadType.fileMetaType"
				name="养老机构消防竣工验收报告"
				uploadTip="上传养老机构消防竣工验收报告"
				:limit="1"
				:multiple="false"
				:disabled="isDetail"
				@change="uploadChange"
			></AplidUpload>
		</div>
		<div style="width: 150px" v-else>
			<FileList :src="modelData.imageList4" :only-ready="true" :showFileList="true"> </FileList>
		</div>

		<div class="f-between">
			<h3>养老机构消防改造审计报告</h3>
		</div>
		<div class="mt12" v-if="!isDetail">
			<AplidUpload
				v-model="modelData.imageList5"
				listType="picture-card"
				:showFileList="false"
				:fileType="uploadType.fileMetaType"
				name="养老机构消防改造审计报告"
				uploadTip="上传养老机构消防改造审计报告"
				:limit="1"
				:multiple="false"
				:disabled="isDetail"
				@change="uploadChange"
			></AplidUpload>
		</div>
		<div style="width: 150px" v-else>
			<FileList :src="modelData.imageList5" :only-ready="true" :showFileList="true"> </FileList>
		</div>
	</div>
</template>

<script setup lang="ts">
import AplidUpload from '@/components/AplidCrud/src/AplidUpload/index.vue'
import FileSaver from 'file-saver'
import apiMod from '@/apiMod/index'
import FileList from '@/components/AplidCrud/src/AplidUpload/PreviewImg/index.vue'
import { uploadType } from '@/utils/util'

const props = defineProps<{
	params?: any
	creditCode?: string | number
	editData?: any
	isDetail?: boolean
	caseId?: string | number
	custome?: boolean
	approvalStatus?: string | number
	activeName?: string
}>()
let modelData = reactive({ imageList1: '' })
const loading = ref(false)

// 去下载模板
const toDownload = () => {
	FileSaver.saveAs('https://aplid-51.oss-cn-hangzhou.aliyuncs.com/1718699768030_725c1e32.docx', '实地勘察报告.docx')
}

let newCaseId = ref('')
const addSave = async () => {
	let date = props.params.belongDate.replace('年', '-').replace('月', '-').split('-')
	let params0 = {
		applyYear: date[0],
		applyMonth: date[1],
		dataContent: {...modelData },
		dataResults: { ...modelData},
		fromId: props.editData.formId,
		fromType: props.activeName,
		tableTemplateId: props.activeName,
		projectId: props.params.subsidyProjectId,
	}
	let res = await apiMod.view_formResults_add(params0)
	newCaseId.value = res.data
}

const eidtSave = () => {
	let query = {
		id: props.editData.result_case_id || newCaseId.value,
		dataContent: {...modelData },
		dataResults: { ...modelData},
		fromId: props.editData.formId,
		fromType: props.activeName,
		tableTemplateId: props.activeName,
		projectId: props.params.subsidyProjectId,
	}
	apiMod.view_formResults_edit(query).then((res) => {
		ElMessage.success('修改成功')
	})
}
const uploadChange = (data) => {
	eidtSave()
}
onMounted(() => {
  
	if (!props.params) {
		return
	}
	// 没有id就进行第一次保存
	if (!props.editData.result_case_id) {
		addSave()
	}
  loading.value = true 
	modelData = props.editData
  loading.value = false

})
</script>
<style scoped lang="scss">
:deep(.el-upload--picture-card) {
	width: 100%;
	height: 100%;
	max-height: 250px;
}
</style>
